#include "PasswordPage.h"

#include "StringEditor.h"
#include "MachineDependents.h"


//, mconfigManager(ConfigManagerSingleton::instance())
PasswordPage::PasswordPage(const int pageNum) : super(pageNum), mauthenticator(AuthenticatorSingleton::instance()) {
    //ctor
}

PasswordPage::~PasswordPage() {
    //dtor
}



void PasswordPage::initEditors() {
    StringEditor* pEditor = new StringEditor(3, 0, 7);    //
//    pEditor->setValue();
    editUnits.push_back(BasicEditorSharedPtr(pEditor));
}



void PasswordPage::setValue() {
//    static_cast<IntEditor*> (editUnits[0].get())->setValue(mloopControllerConfig.switchInterval);
}


/**
 * 设置时间数据
 */
void PasswordPage::saveValue() {
    StringEditor* stringEditor = static_cast<StringEditor*> (editUnits[0].get());
    const std::string verifyCode = stringEditor->getValue();
    stringEditor->setValue(StringUtility::EMPTY_STRING);

    mauthenticator.authenticate(verifyCode);
}



void PasswordPage::paint() {
    if (focus) {
        EditablePage::paint();
    } else {
        std::string content[4];
        resetStream();
        strStream << "unlockSystem" << std::setw(3) << pageNum;
        content[0] = strStream.str();
        resetStream();
        strStream << "status:" << LOCK_STATUS[mauthenticator.mpermit];
        content[1] = strStream.str();

        content[2] = "password:";
//        resetStream();
//        content[2] = strStream.str();
        screen.show(&content[0], &content[1], &content[2], &content[3]);
    }
}


